import {createRouter, createWebHistory} from 'vue-router'


const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {path: '/', redirect: '/login'},
        {
            path: '/manager', component: () => import('../views/Manager.vue'), children: [
                {path: 'home', name: 'home', meta: {title: '主页'}, component: () => import('../views/Home.vue')},
                {path: 'test', name: 'test', meta: {title: '测试页'}, component: () => import('../views/Test.vue')},
                {path: 'data', name: 'data', meta: {title: '数据展示页'}, component: () => import('../views/Data.vue')},
                {path: 'employee', name: 'employee', meta: {title: '员工信息'}, component: () => import('../views/Employee.vue')},
                {path: 'admin', name: 'admin', meta: {title: '管理员信息'}, component: () => import('../views/Admin.vue')},
                {path: 'person', name: 'person', meta: {title: '个人信息'}, component: () => import('../views/Person.vue')},
                {path: 'password', name: 'password', meta: {title: '修改密码'}, component: () => import('../views/Password.vue')},
                {path: 'article', name: 'article', meta: {title: '文章信息'}, component: () => import('../views/Article.vue')},
                {path: 'department', name: 'department', meta: {title: '部门信息'}, component: () => import('../views/Department.vue')},


            ]
        },
        {path: '/login', name: 'Login', meta: {title: '登录'}, component: () => import('../views/Login.vue')},
        {path: '/register', name: 'Register', meta: {title: '注册'}, component: () => import('../views/Register.vue')},
        {path: '/404', name: 'NotFound', meta: {title: '404'}, component: () => import('../views/404.vue')},
        {path: '/:pathMatch(.*)', redirect: '/404'}

        //嵌套路由中子路由前不用写/，会自动添加。meta是附加信息，可写可不写
        // {path: '/home', name: 'home', component: () => import('../views/Home.vue')},
        // {path: '/test', name: 'test', component: () => import('../views/Test.vue')},

    ],
})
//beforeeach表示跳转前的操作
router.beforeEach((to, from, next) => {
    document.title = to.meta.title
    next() //必须调用这个函数才能跳转

})

export default router
